package com.qf.controller;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.qf.dao.StudentMapper;
import com.qf.service.StudentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.core.env.Environment;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Arrays;
import java.util.List;

@RestController
@RequestMapping("/stu")
@EnableConfigurationProperties(Student.class)
public class StuController {

    @Value("${stu.name}")
    private String name;

    @Value("${stu.age}")
    private Integer age;

    @Value("${stu.hobbies[0]}")
    private String hobbies0;

    @Value("${stu.hobbies2[1]}")
    private String hobbies21;

    @Autowired
    private Environment environment;

    @Autowired
    private Student stu;


    @Autowired
    private StudentService studentService;

    @GetMapping("/findAll")
    public PageInfo<com.qf.entity.Student> findAll(){

        int i = 1/0;

        return studentService.findPage(1,2);
    }


    @GetMapping
    public void getVal(){
        System.out.println(name);
        System.out.println(age);
        System.out.println(hobbies0);
        System.out.println(hobbies21);
        System.out.println("================");
        String property = environment.getProperty("stu.name");
        System.out.println("name:" + property);

        Integer age = environment.getProperty("stu.age", Integer.class);
        System.out.println("age:" + age);

//        String[] sts = environment.getProperty("stu.hobbies", String[].class);
//        System.out.println(Arrays.toString(sts));
        String hobbies0 = environment.getProperty("stu.hobbies[0]");
        System.out.println(hobbies0);

        System.out.println("================");
        System.out.println(stu);
    }
}
